//
//  FriendsViewController.m
//  shusheng
//
//  Created by rimi on 16/7/9.
//  Copyright © 2016年 yuying. All rights reserved.
//

#import "FriendsViewController.h"
#import "FriendTableViewCell.h"
#import "ChatViewController.h"
#import "CDFriendListVC.h"

@interface FriendsViewController ()<UITableViewDataSource,UITableViewDelegate>

- (void)initializeUserInterface; /** < 初始化用户界面 */
- (void)addMasonry;
@property (nonatomic, strong) UITableView *friendTableView; // 好友

@end

@implementation FriendsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initializeUserInterface];
}

- (void)initializeUserInterface{
    [self.view addSubview:self.friendTableView];
    
    
    
    [self addMasonry];
}


#pragma mark -- getter
- (UITableView *)friendTableView{
    if (!_friendTableView) {
        _friendTableView = [[UITableView alloc] init];
        _friendTableView.dataSource = self;
        _friendTableView.delegate = self;
        _friendTableView.rowHeight = SCREEN_HEIGHT*0.12;
    
    }
    return _friendTableView;
}

#pragma mark -- 添加约束
- (void)addMasonry{
    [self.friendTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).with.offset(64);
        make.left.equalTo(self.view).with.offset(0);
        make.bottom.equalTo(self.view).with.offset(0);
        make.right.equalTo(self.view).with.offset(0);
    }];
}

#pragma mark -- UITableViewDataSource && UITableViewDelegate

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 20;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    FriendTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"FriendTableViewCell"];
//    FriendTableViewCell *cell = [[FriendTableViewCell alloc] init];
    cell  = [[[NSBundle mainBundle] loadNibNamed:@"FriendTableViewCell" owner:nil options:nil] lastObject];
    cell.nameLabel.text = @"qqqqwwwww";
    cell.headImageView.image = [UIImage imageNamed:@"image.jpg"];
//    cell = [tableView dequeueReusableCellWithIdentifier:@"FriendTableViewCell"];
    return cell;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
//    ChatViewController *chatVc = [[[NSBundle mainBundle] loadNibNamed:@"ChatViewController" owner:nil options:nil] lastObject];
//    ChatViewController *chatVc = [self.storyboard  instantiateViewControllerWithIdentifier:@"ChatViewController"];
    CDFriendListVC *chatVc = [[CDFriendListVC alloc] init];
//
//    [self.navigationController pushViewController:chatVc animated:YES];
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
////    _editorVC = [self.storyboard instantiateViewControllerWithIdentifier:@"EditorViewController"];//编辑vc
    [self addChildViewController:chatVc];
    [self.view addSubview:chatVc.view];

}

#pragma mark -- Action

- (IBAction)responBtn:(UIButton *)sender {
    NSLog(@"返回");
    [self.view removeFromSuperview];
    [self removeFromParentViewController];
}

- (IBAction)addFriends:(UIButton *)sender {
    NSLog(@"添加好友");
}


@end
